package com.venta.autopartes.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.venta.autopartes.car.PaymentMethod;
import com.venta.autopartes.car.PaymentType;

public class PaymentDAO extends BaseDAO{

	private static final String SELECT_PAYMENT_METHOD="SELECT venau_payment_method_catalog_id AS ID, venau_payment_method_catalog_name as NAME FROM SGDLS_T_payment_method_catalog ORDER BY venau_payment_method_catalog_name";
	private static final String SELECT_PAYMENT_CATALOG="SELECT venau_payment_catalog_id AS ID, venau_payment_catalog_name AS NAME FROM SGDLS_T_payment_catalog ORDER BY venau_payment_catalog_name";
	
	public static List<PaymentMethod> getPaymentMethodList() {
		List<PaymentMethod> paymentMethodList = new ArrayList<PaymentMethod>();

		connection = com.venta.autopartes.utils.Connection.getConnection();
		try {
			preparedStatement = connection.prepareStatement(SELECT_PAYMENT_METHOD);
			resultSet = preparedStatement.executeQuery();

			while (resultSet.next()) {
				PaymentMethod paymentMethod = new PaymentMethod(resultSet.getInt("ID"), resultSet.getString("NAME"));
				paymentMethodList.add(paymentMethod);
			}

		} catch (SQLException sqlException) {
			System.out.println("(Class)PaymentDAO - (ErrorType)sqlException");
			sqlException.printStackTrace();
			try {
				connection.rollback();
			} catch (Exception exception) {
				System.out.println("(Class)PaymentDAO - (ErrorType)exception");
				exception.printStackTrace();
			}
		}finally{
			closeConnection();
		}

		return paymentMethodList;
	}
	
	public static List<PaymentType> getPaymentTypeList(){
		List<PaymentType> paymentTypeList=new ArrayList<PaymentType>();

		connection = com.venta.autopartes.utils.Connection.getConnection();
		try{
			preparedStatement = connection.prepareStatement(SELECT_PAYMENT_CATALOG);
			resultSet=preparedStatement.executeQuery();
			
			while (resultSet.next()) {
				PaymentType paymentType= new PaymentType(resultSet.getInt("ID"),resultSet.getString("NAME"));
				paymentTypeList.add(paymentType);
			}
			
		}catch(SQLException sqlException){
			System.out.println("(Class)PaymentDAO - (ErrorType)sqlException");
			sqlException.printStackTrace();
			try{
				connection.rollback();
			}catch(Exception exception){
				System.out.println("(Class)PaymentDAO - (ErrorType)exception");
				exception.printStackTrace();
			}
		}finally{
			closeConnection();
		}
		
		return paymentTypeList;
	}
	
}
